package biblioteca.conection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public abstract class GenericDao {
	
	public GenericDao(){
		carregaDriver();
	}
	
	private Connection conexao; 
	
	private void carregaDriver(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public Connection getConexao() {
		if (this.conexao == null){
			try {
				this.conexao = DriverManager.getConnection("jdbc:mysql://localhost/Java?user=root&password=");
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return conexao;
	}
	
	public void fechaConexao(){
		try {
			this.conexao.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
